#!/usr/bin/env python
# encoding: utf-8
# @author: liusir
# @file: common_function.py
# @time: 2021/6/27 4:39 下午

import os
import requests
import jsonpath
from common.config import Config
from common.config_utils import ConfigUtils
from common.common_api_info import CommonApiInfo

current_path = os.path.dirname( os.path.abspath(__file__) )
config_file_dir = os.path.join( current_path ,'..','conf','config.ini' )

def set_token_to_ini_file():
    session = requests.session()
    response_obj = CommonApiInfo( session ).get_access_token_api("client_credential",
                                                                 "wx55614004f367f8ca",
                                                                 "65515b46dd758dfdb09420bb7db2c67f")
    json_body = response_obj.json()
    token_value = jsonpath.jsonpath(json_body, '$.access_token')[0]
    ConfigUtils(config_file_dir).write_value('default', 'token_value', token_value)
    response_obj.close()